package com.tjp.eight.ui.fragment.rank;

import com.tjp.eight.AllRetrofit;
import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;
import com.tjp.eight.ui.fragment.tabFind.FindResultModel;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/2/17.
 */

public class RankPresenter extends BasePresenterImpl<RankView> {
    private RankService rankService = AllRetrofit.getRetrofit(UrlConstant.BaseUrl).create(RankService.class);

    public RankPresenter(RankView rankView) {
        attachView(rankView);
    }

    public void loadData(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(rankService.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<FindResultModel>() {
            @Override
            public void onSuccess(FindResultModel model) {
                view.loadData(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
